package com.hd.persistence.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.hd.common.DataPage;
import com.hd.common.HibernateEntityDao;
import com.hd.persistence.model.AssignRecord;

public class AssignRecordDao extends HibernateEntityDao<AssignRecord> {
	
	public DataPage<AssignRecord> pageQueryAssignRecords(int pageNo, int pageSize) {
		String hql = new String("from AssignRecord ");
		return pagedQuery(hql, pageNo, pageSize);
	}
	
	public DataPage<AssignRecord> pageQueryAssignRecords(String unitName, String unitForShort, String machineModel, String repairman, Date workday, int pageNo, int pageSize) {
		StringBuilder hql = new StringBuilder("from AssignRecord where (1=1) ");
		List<Object> objs = new ArrayList<Object>();
		if ( StringUtils.isNotBlank(unitName) ) {
			hql.append("and unitName=? ");
			objs.add(unitName);
		}
		if ( StringUtils.isNotBlank(unitForShort) ) {
			hql.append("and unitForShort=? ");
			objs.add(unitForShort);
		}
		if ( StringUtils.isNotBlank(machineModel) ) {
			hql.append("and machineModel=? ");
			objs.add(machineModel);
		}
		if ( StringUtils.isNotBlank(repairman) ) {
			hql.append("and repairman=? ");
			objs.add(repairman);
		}
		if ( workday != null ) {
			hql.append("and workday=? ");
			objs.add(workday);
		}
		return pagedQuery(hql.toString(), pageNo, pageSize, "workday", false, objs.toArray());
	}

}
